//引入样式
require('../less/courseDescription.less')

//引入字体样式
require('../fonts/iconfont.css')



//文档加载事件
document.ready(function () {


    //获取
    const getback = document.querySelector('#getback')
    const Img = document.querySelector('#Img')
    const desc = document.querySelector('#desc')
    const name = document.querySelector('#name')
    const btn = document.querySelector('#btn')


    //判断用户是否登录
    until.isLogin()

    //点击返回上一页
    getback.addEventListener('click', function () {
        location.href = "./course.html"
    })


    //获取当前课程id
    function getCourseDescriptionId() {
        let id = location.search.split('=')[1];


        //发请求
        $http.get(`/sports/courseDetail?id=${id}`, function (res) {


            if (res.status === 0) {

                //把数据保存到本地存储
                let fras = localStorage.setItem('fragments', res.data.fragments)
                console.log(fras);



                //将课程id保存到本地存储
                localStorage.setItem('course', id)

                //视频片段
                const fragments = res.data.fragments


                //将视频片段存储到本地
                localStorage.setItem('fragments', JSON.stringify(fragments))

                //渲染到页面
                Img.textContent = `http://139.9.177.51:8099${res.data.imgurl}`
                desc.textContent = res.data.desc
                name.textContent = res.data.name
            }
        })
    }
    getCourseDescriptionId()




    //点击跳转到课程
    btn.addEventListener('click', function () {

        
        
        location.href = "drill.html"
    })





})